package com.zdy.state;

/**
 * Created by 逸足天涯
 * on 3/8/2020.
 */
//出现线程并发问题（该程序线程不安全）
public class TestSleep implements Runnable{

    private int tickNums = 10;

    @Override
    public void run() {
        while(true){
            if(tickNums <= 0){break;}
            //模拟延迟
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "-->拿到了第" + tickNums-- +"票");
        }
    }

    public static void main(String[] args) {
        //多个线程操作同一个对象，模拟网络延迟放大问题的发生性
        System.out.println("创建线程");
        TestSleep tickets = new TestSleep();
        new Thread(tickets,"小明").start();
        new Thread(tickets,"老师").start();
        new Thread(tickets,"黄牛党").start();
    }
}
